﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using System.Diagnostics;

namespace Compiled_Tests.AutomationAbstractions
{
    public class AEWrapper : IDisposable
    {
        public AEWrapper(AutomationElement ae)
        {
            this.ae = ae;
        }

        public virtual String ID { get { return ae.Current.AutomationId; } }
        public virtual String Name { get { return ae.Current.Name; } }
        public virtual String Class { get { return ae.Current.ClassName; } }
        protected virtual AEWrapper Wrap(AutomationElement element) { return new AEWrapper(element); }
        public virtual AEWrapper Parent { get {
            AutomationElement parent = TreeWalker.ControlViewWalker.GetParent(ae);
            if (parent == null)
                return null;
            return Wrap(parent); 
        } }
        public virtual int ProcessID { get { return ae.Current.ProcessId;  } }
        public void Dispose() { ae = null; }
        public virtual bool TryGetCurrentPattern(AutomationPattern pattern, out Object obj) { return ae.TryGetCurrentPattern(pattern, out obj); }
        public virtual bool IsEnabled { get { return ae.Current.IsEnabled; } }
        public virtual AutomationElement ae { get; private set; }

        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is AEWrapper))
                return false;

            return ae.Equals((obj as AEWrapper).ae);
        }

        public override int GetHashCode()
        {
            return ae.GetHashCode();
        }
    }
}
